package com.zackeus.sipservice.entity;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
 * 流统计
 * @name: RtpStreamStats
 * @author: zz
 * @date: 2022/10/10
 */
public class RtpStreamStats implements Parcelable {

    /* 总数量 */
    private final long pkt;
    /* 总负载/字节数 */
    private final long bytes;
    /* 丢弃数据包总数 */
    private final long discard;
    /* 丢包总数 */
    private final long loss;
    /* 总数不合格的数据包 */
    private final long reorder;
    /* 重复数据包总数 */
    private final long dup;
    /* 抖动统计 */
    private final Jitter jitter;

    public RtpStreamStats(long pkt, long bytes, long discard, long loss, long reorder, long dup, Jitter jitter) {
        this.pkt = pkt;
        this.bytes = bytes;
        this.discard = discard;
        this.loss = loss;
        this.reorder = reorder;
        this.dup = dup;
        this.jitter = jitter;
    }

    public long getPkt() {
        return pkt;
    }

    public long getBytes() {
        return bytes;
    }

    public long getDiscard() {
        return discard;
    }

    public long getLoss() {
        return loss;
    }

    public long getReorder() {
        return reorder;
    }

    public long getDup() {
        return dup;
    }

    public Jitter getJitter() {
        return jitter;
    }

    // This is used to regenerate the object.
    // All Parcelables must have a CREATOR that implements these two methods
    public static final Parcelable.Creator<RtpStreamStats> CREATOR =
            new Parcelable.Creator<RtpStreamStats>() {
                @Override
                public RtpStreamStats createFromParcel(final Parcel in) {
                    return new RtpStreamStats(in);
                }

                @Override
                public RtpStreamStats[] newArray(final int size) {
                    return new RtpStreamStats[size];
                }
            };

    private RtpStreamStats(Parcel in) {
        this.pkt = in.readLong();
        this.bytes = in.readLong();
        this.discard = in.readLong();
        this.loss = in.readLong();
        this.reorder = in.readLong();
        this.dup = in.readLong();
        this.jitter = in.readParcelable(Jitter.class.getClassLoader());
    }

    public void writeToParcel(Parcel parcel, int arg1) {
        parcel.writeLong(pkt);
        parcel.writeLong(bytes);
        parcel.writeLong(discard);
        parcel.writeLong(loss);
        parcel.writeLong(reorder);
        parcel.writeLong(dup);
        parcel.writeParcelable(jitter, 0);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @NonNull
    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this);
    }
}
